﻿﻿using APIService.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using APIService.Common;
using System.Data;

namespace APIService.Repository
{
    public class UserRepository
    {
        private EFEntities db = new EFEntities();
        public IQueryable<TestUser> Users
        {
            get { return db.TestUsers; }
        }

        public bool Insert(TestUser model)
        {
            var entity = new TestUser
            {
                UserName = model.UserName,
                Address = model.Address,
                CreateTime = model.CreateTime
            };

            db.Entry<TestUser>(entity).State = EntityState.Added;
            return db.SaveChanges() > 0;
        }

        public bool Update(TestUser model)
        {
            TestUser user = db.TestUsers.FirstOrDefault(t => t.Id == model.Id);
            user.UserName = model.UserName;
            user.Address = model.Address;
            user.CreateTime = model.CreateTime;
            return db.SaveChanges() > 0;
        }

        public bool Delete(TestUser model)
        {
            db.Set<TestUser>().Remove(model);
            return db.SaveChanges() > 0;
        }
    }
}